/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geotools.geosearch;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geotools.multithread.TaskFindPath;

/**
 *
 * @author oleg
 */
public class GuideSingleton {
    
    static private Guide instance;

    private static ExecutorService pool = Executors.newCachedThreadPool();//newFixedThreadPool(3);
    private static Guide instances[]=null;
    private static BlockingQueue<Guide> free;
    
    public static Guide getInstance(String filepath)
    {
        if(instance==null)
            instance=Guide.fromFile(filepath);
        
        return instance;
    }

    public static String getPathJSON(double points[])
    {
        /*
        try {
            if (instances == null) {
                instances = new Guide[8];
                free = new ArrayBlockingQueue<Guide>(8);
                for (Guide guide : instances) {
                    guide = new Guide(null);
                    free.put(guide);
                }
            }
            
        } catch (InterruptedException ex) {
            Logger.getLogger(GuideSingleton.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            Guide g = free.take();
            TaskFindPath task = new TaskFindPath(g, points);
            Future<String> submit = pool.submit(task);
            String get = submit.get();
            free.put(task.getGuide());
            return get;
        } catch (ExecutionException ex) {
            Logger.getLogger(GuideSingleton.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(GuideSingleton.class.getName()).log(Level.SEVERE, null, ex);
        }
*
        if (instances == null) {
                instance = new Guide();
        }
         return instance.guidanceJSONMultiple(points);
         *
         */
        return null;
         
         
    }
}
